﻿@using PayrollExpress.Helpers;
@using PayrollExpress.Models;
@model UserListModel

@Html.Partial("_BreadCrumb", Model.BreadCrumb)

@using (Html.BeginForm(BaseHelper.PageAddEditSave.UsersRefresh.ToString(), Model.ControllerName, FormMethod.Post, new { id = "saveForm" }))
{
    @Html.AntiForgeryToken()

    <fieldset>
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="row">
            <div class="col-lg-8">
                <div class="ibox float-e-margins">
                    <div class="ibox-title">
                        <div class="row">
                            <div class="col-lg-3">
                                @Html.DropDownListFor(m => m.SelectedWorkLocationID, Model.WorkLocations, new { @class = "form-control input", @onchange = "Refresh()" })
                                <button id="btnSearch" type="submit" class="hidden" name="command" value="Refresh"></button>
                            </div>
                            <div class="col-lg-9">
                                @Html.ActionLink(BaseHelper.PageAction.Add.ToString(), BaseHelper.PageAddEditSave.UserAddEdit.ToString(), Model.ControllerName, new { workLocationID = Model.SelectedWorkLocationID }, new { @class = "btn btn-primary" })
                            </div>
                        </div>
                    </div>
                    <div class="ibox-content">
                        <table class="table table-striped table-bordered table-hover table-List">
                            <thead class="header">
                                <tr>
                                    <th>@AdministrationHelper.ListHeaders.UserName.ToDescription()</th>
                                    <th>@AdministrationHelper.ListHeaders.WorkLocationName.ToDescription()</th>
                                    <th>@AdministrationHelper.ListHeaders.Role.ToDescription()</th>
                                    <th>@AdministrationHelper.ListHeaders.IsActive.ToDescription()</th>
                                    <th></th>
                                </tr>
                            </thead>
                            <tbody>
                                @for (var i = 0; i < Model.ListItems.Count(); i++)
                        {
                        <tr>
                            <td>@Html.DisplayFor(m => Model.ListItems[i].UserName)</td>
                            <td>@Html.DisplayFor(m => Model.ListItems[i].WorkLocationName)</td>
                            <td>@Html.DisplayFor(m => Model.ListItems[i].RoleName)</td>
                            <td>@Html.DisplayFor(m => Model.ListItems[i].IsActiveYesNo)</td>
                            <td>@Html.ActionLink(BaseHelper.PageAction.Edit.ToDescription(), BaseHelper.PageAddEditSave.UserAddEdit.ToString(), Model.ControllerName, null, null, null, new { workLocationID = Model.ListItems[i].WorkLocationID, id = Model.ListItems[i].ID }, new { @class = "btn btn-primary btn-sm" })</td>
                        </tr>
                        }
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
</fieldset>
}

@section Styles {
    @Styles.Render("~/Content/plugins/dataTables/dataTablesStyles")
}

@section Scripts {
    @Scripts.Render("~/plugins/dataTables")

    <script type="text/javascript">

        $(document).ready(function () {
            $('.table-List').dataTable();
        });

        function Refresh() {
            document.getElementById('btnSearch').click();
        }

    </script>
}
